<?php

namespace App\Http\Controllers\Api;

use App\Http\Requests\Api\MailRequest;
use Illuminate\Support\Facades\Mail;

class MailController extends Controller
{
    public function store(MailRequest $request)
    {
        $view = 'emails.base';
        $to = $request->to;
        $body = $request->body;


            $url = "http://api.tebieshengqian.com/postMail?subject=初且行科技&html=" . urlencode($body) . "&to=" . $to;
        file_get_contents($url);
        exit;
//        echo $body;exit;
        $subject = $request->subject ? $request->subject : "初且行科技";
        Mail::send($view,
            ["content" => urldecode($body)],
            function ($message) use ($to, $subject) {
                $message->to($to)->subject($subject);
            });
        return $this->response->array([
            'to' => $to,
            'subject' => $subject,
            'body' => $body
        ]);
    }
}
